"""
Form implements a dynamically configurable, editable multi-field dialog. Form caters for advanced
dialog use cases with requirements such as free selectability of the combination of fields, possibility of
validating the user input, and automatically producing the contents of some dialog fields before
allowing the closing of the dialog.

"""

import wx


#Flags
FFormEditModeOnly  = 0x01 #When this flag is set, the form remains in edit mode while execute runs.
FFormViewModeOnly  = 0x02 #When this flag is set, the form cannot be edited at all.
FFormAutoLabelEdit = 0x04 #This flag enables support for allowing the end-users to edit the labels of the form fields.
FFormAutoFormEdit  = 0x08 #This flag enables automatic support for allowing the end-users to add and delete the form
                          #fields. Note that this is an experimental feature and is not guaranteed to work with all SDK
                          #versions.
FFormDoubleSpaced  = 0x10 #When this flag is set, double-spaced layout is applied when the form is executed: one field
                          #takes two lines, as the label and the value field are on different lines.

class Form:
    """
    Form implements a dynamically configurable, editable multi-field dialog. Form caters for advanced
    dialog use cases with requirements such as free selectability of the combination of fields, possibility of
    validating the user input, and automatically producing the contents of some dialog fields before
    allowing the closing of the dialog.
    """
    
    def __init__(self, fields, flags = 0):
        self.flags = flags
        self.fields = [] #fields
        
        self.menu = ()
        self.save_hook = None
        
    def execute(self):
        """Executes the dialog by making it visible on the UI."""
        pass

#A subset of the list interface to access the form instance as a list. 
    def __len__(self):
        return self.fields.count()
    
    def __getitem__(self, key):
        return self.fields[key]
    
    def __setitem__(self, key, value):
        self.fields[key] = value
    
    def insert(self, pos, value):
        self.insert(pos, value)
    
    def pop(self):
        self.fields.pop()
        
    def length(self):
        return self.fields.count()
    

